package com.mtons.mblog.base.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @ClassName: RedisHelper
 * @Auther: Jerry
 * @Date: 2020/5/21 16:24
 * @Desctiption: TODO
 * @Version: 1.0
 */
@Component
public class RedisHelper {

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public Map<Object, Object> getHash(String key){
        return redisTemplate.opsForHash().entries(key);
    }

    public Object hget(String key, String hashKey){
        return redisTemplate.opsForHash().get(key, hashKey);
    }

    public void hset(String key, String hashKey, Object value){
        redisTemplate.opsForHash().put(key, hashKey, value);
    }

    public void hdel(String key, String...hashKeys) {    //...代表可以有一个参数，也可以有多个参数！
        redisTemplate.opsForHash().delete(key, hashKeys);
    }

    public Long hLen(String key) {
        return redisTemplate.opsForHash().size(key);
    }
}
